package cn.znzz.cjm.basic.service.impl;

import cn.znzz.cjm.basic.mapper.BaseMapper;
import cn.znzz.cjm.basic.query.BaseQuery;
import cn.znzz.cjm.basic.service.IBaseService;
import cn.znzz.cjm.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

//@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T>{
    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    @Transactional
    public void add(T t) {
        baseMapper.save(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    @Transactional
    public void remove(Long id) {
        baseMapper.delete(id);
    }

    @Override
    public T findById(Long id) {

        return baseMapper.loadById(id);
    }

    @Override
    public List<T> findAll() {
        return baseMapper.loadAll();
    }

    @Override
    public PageList<T> queryPage(BaseQuery query) {
        //查询总条数
        Long total = baseMapper.queryCount(query);
        //查询当前页数
        List<T> rows = baseMapper.queryData(query);
        return new PageList<>(total,rows);
    }

    @Override
    public void batchRemove(List<Long> ids) {
        baseMapper.batchRemove(ids);
    }
}
